//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//
//int main()
//{
//    FILE* pf = fopen("bite", "w+");
//    if(pf == NULL)
//    {
//        perror("pf");
//        exit(1);
//    }
//    const char* str = "linux so easy!";
//    fwrite(str, strlen(str), 1, pf);
//    fseek(pf, 0, SEEK_SET);
//    char buffer[64];
//    fread(buffer, strlen(buffer), 1, pf);
//    printf("%s\n", buffer);
//    fclose(pf);
//    return 0;
//}


//#include <stdio.h>
//#include <sys/types.h>
//#include <sys/stat.h>
//#include <fcntl.h>
//#include <stdlib.h>
//#include <string.h>
//
//int main()
//{
//    int fd = open("bite", O_WRONLY | O_CREAT | O_TRUNC, 0666);
//    if(fd < 0)
//    {
//        perror("fd");
//        exit(1);
//    }
//    const char* str = "I like linux!";
//    write(fd, str, strlen(str));
//    close(fd);
//    fd = open("bite", O_RDONLY);
//    char buffer[64];
//    int len = read(fd, buffer, strlen(buffer));
//    buffer[len] = '\0';
//    printf("%s\n", buffer);
//    return 0;
//}



//#include <stdio.h>
///#include <stdlib.h>
///#include <string.h>
///int main()
///{
///	FILE* pf = fopen("bite", "w");
///	if (pf == NULL)
///	{
///		perror("pf");
///		exit(1);
///	}
///	const char* str = "linux so easy!";
///	fwrite(str, sizeof(char), strlen(str), pf);
///	pf = freopen("bite", "r", pf);
///	if (pf == NULL)
///	{
///		perror("pf");
///		exit(1);
///	}
///	char buffer[64];
///	size_t ret = fread(buffer, 1, strlen(str), pf);
///	if (ret > 0)
///	{
///		buffer[ret] = '\0';
///		printf("%s\n", buffer);
///	}
///	fclose(pf);
///
///	return 0;
///}
///

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int fd = open("bite", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    if(fd < 0)
    {
        perror("fd");
        exit(1);
    }
    const char* str = "I like linux!";
    int sz = strlen(str);
    write(fd, str, sz);
    close(fd);
    fd = open("bite", O_RDONLY);
    if(fd < 0)
    {
        perror("fd");
        exit(1);
    }
    char buffer[64];
    ssize_t ret = read(fd, buffer, sz);
    if(ret == sz)
    {
        buffer[sz] = '\0';
        printf("%s\n", buffer);
    }
    return 0;
}
